<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item> <i class="el-icon-lx-cascades"></i> 用户列表 </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
            <div class="handle-box">
                <el-button type="primary" icon="el-icon-delete" class="handle-del mr10" @click="delAllSelection">批量删除</el-button>
                <el-select v-model="query.address" placeholder="地址" class="handle-select mr10">
                    <el-option key="1" label="广东省" value="广东省"></el-option>
                    <el-option key="2" label="湖南省" value="湖南省"></el-option>
                </el-select>
                <el-input v-model="query.name" placeholder="用户名" class="handle-input mr10"></el-input>
                <el-button type="primary" icon="el-icon-search" @click="handleSearch">搜索</el-button>
                <el-button type="primary" icon="el-icon-search" @click="Tj">给角色分配权限</el-button>
            </div>
            <el-table
                ref="multipleTable"
                :data="tableData"
                tooltip-effect="dark"
                style="width: 100%"
                @selection-change="handleSelectionChange"
            >
                <el-table-column type="selection" width="55"> </el-table-column>
                <el-table-column fixed prop="RoleName" label="角色名称" width="150"> </el-table-column>
                <el-table-column prop="RolePerm" label="角色纤细" width="200"> </el-table-column>
                <el-table-column prop="RoleDeta" label="创建时间" width="150"> </el-table-column>
                <el-table-column label="操作" width="180" align="center">
                    <template slot-scope="scope">
                        <el-button type="text" icon="el-icon-edit" @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
                        <el-button type="text" icon="el-icon-delete" class="red" @click="Sc(scope.row.Id)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.pageIndex"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>

        <!---弹出框-->
        <el-dialog v-bind="$attrs" v-on="$listeners" @open="onOpen" @close="onClose" :visible.sync="RoleTan">
            <el-tree
                :data="data"
                show-checkbox
                node-key="Id"
                :default-expanded-keys="[2, 3]"
                :props="{ label: 'PermName', value: 'PId', children: 'Children' }"
            >
            </el-tree>
            <div slot="footer">
                <el-button @click="RoleTan = false">取消</el-button>
                <el-button type="primary" @click="handelConfirm">确定</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>
import { RolePermShow, RolePermDel } from '@/api/user';

export default {
    name: 'user',
    data() {
        return {
            query: {
                address: '',
                name: '',
                pageIndex: 1,
                pageSize: 10
            },
            tableData: [], //表格数据
            multipleSelection: [],
            delList: [],
            editVisible: false,
            pageTotal: 0, //总条数
            form: {},
            idx: -1,
            id: -1,
            RoleTan: false,
            data: [],
            multipleSelection: [],
            defaultProps: {
                children: 'children',
                PermName: 'PermName'
            }
        };
    },
    mounted() {
        this.getData();
    },
    methods: {
        //获取用户列表
        getData() {
            RolePermShow().then((res) => {
                console.log(res);
                this.tableData = res.Data;
                this.pageTotal = res.totalCount;
            });
        },
        Sc(id) {
            if (confirm('是否确认删除') == true) {
                this.$ajax.post('http://localhost:21493/api/Role/RoleDel?Ids=' + id).then((str) => {
                    alert(str.data.Msg);
                    this.getData();
                });
            }
            // RolePermDel(id).then((str) => {
            //     alert(str.Msg);
            //     this.getData();
            // });
        },
        Tj() {
            console.log(this.multipleSelection);
            if (this.multipleSelection.length > 1) {
                alert('最多选择一条数据!');
            } else {
                if (this.multipleSelection.length < 1) {
                    alert('最少选择一条数据!');
                } else {
                    this.$ajax.get('http://localhost:21493/api/Perm/PermShow').then((str) => {
                        this.data = str.data;
                        console.log(this.data);
                        alert(this.data);
                    });
                    this.RoleTan = true;
                }
            }
        },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'pageIndex', val);
            this.getData();
        },
        close() {
            RoleTan = false;
        },
        handleSelectionChange(val) {
            this.multipleSelection = val;
        },
        handelConfirm()
        {
            this.RoleTan = false;
            alert("添加成功!");
        }
    }
};
</script>

<style scoped>
.handle-box {
    margin-bottom: 20px;
}

.handle-select {
    width: 120px;
}

.handle-input {
    width: 300px;
    display: inline-block;
}
.table {
    width: 100%;
    font-size: 14px;
}
.red {
    color: #ff0000;
}
.mr10 {
    margin-right: 10px;
}
.table-td-thumb {
    display: block;
    margin: auto;
    width: 40px;
    height: 40px;
}
</style>
